<template>
  <div class="subject">
    <span>{{ sum }}</span>
    <span>+</span>
    <span>{{ sum1 }}</span>
    <span>=</span>
    <input type="number" v-model="msg" />
    <button @click="add($event)">提交</button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      msg: "",
    };
  },
  props: ["index"],
  computed: {
    sum() {
      return Math.floor(Math.random() * 10);
    },
    sum1() {
      return Math.floor(Math.random() * 20);
    },
  },
  methods: {
    add(e) {
      e.target.setAttribute("disabled", true);
      this.$bus.$emit(
        "count",
        this.sum + this.sum1 === this.msg * 1,
        this.index
      );
    },
  },
};
</script>

<style scoped>
.subject {
  margin: 5px;
  padding: 5px;
  font-size: 20px;
}
.subject span {
  display: inline-block;
  text-align: center;
  width: 20px;
}
.subject input {
  width: 50px;
  height: 20px;
}
</style>